package timing.ukulele.bridge.utils;


import lombok.extern.slf4j.Slf4j;
import timing.ukulele.common.util.CryptoUtils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

@Slf4j
public class SecurityUtils {
    private SecurityUtils() {
        // 禁止实例化工具类
        throw new UnsupportedOperationException("Utility classes cannot be instantiated.");
    }

    public static String decrypt(String encryptString, String privateKey) {
        try {
            String result = CryptoUtils.decryptByRSA(privateKey, encryptString);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String getContentData(String path) {
        InputStream ins = SecurityUtils.class.getClassLoader().getResourceAsStream(path);
        if (ins == null) {
            return "";
        }
        try {
            BufferedReader tBufferedReader = new BufferedReader(new InputStreamReader(ins));
            StringBuilder tStringBuffer = new StringBuilder();
            String sTempOneLine;
            while ((sTempOneLine = tBufferedReader.readLine()) != null) {
                tStringBuffer.append(sTempOneLine);
            }
            return tStringBuffer.toString();
        } catch (Exception ex) {
            log.error("getContentData", ex);
        }
        return "";
    }

    public static void main(String[] args) throws Exception {
        String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAI+iAycmXZ0NT+zjj8Tfm1sblFQ9N/L4VXDToAGE9NnO0rrOawmQv4QNLc7ycAUuF35BiZSepiA54ZEy+uxDyVGPS+MvYRf3maWJwqO4pqjFfkocH6+JHOOoV9AfcBPSto9O3lR9FrdwFeQcrUSdXBZ//JK/d8Pc5V6WRG8J2V+fAgMBAAECgYBfWMxBA+3m4Lxq49E/frSRsWgw14a5ivKk+EbiW1Fy+SHYkkhpzCXmUh1ToIqOVb+Qt47OEtby05mSmsYJayJLOwOxTL5+2deIii5SrlEQqesACgMneam3lckkblH4aDx6RuseSplnM3Swj/lDwqEjH5fT1+0Ass3x29XQ6Jf1IQJBANWay2gau0nUykFoeLF1Vb7RLnegMU6YFlmOk1hnrCnRSkaeudeJkCAEY4ApmZfm12SrETzc9z183I9DDx/qp/ECQQCsI/dGwtw6BVvhrq4s6DwKsnyO6biPwL0j8YnLoEzQYWXMzVcGaPvDZyM+8qMki7htNKn6f/Z9vuwKqtiqLpCPAkEAycN9fshBQGwO39mep4D9jVBpY/WcnXBrLAzQgSDsLlPSpQIo6L63tIZwtg6VVjZmHmC315WgtCPM8kWVc8BjAQJATk6qLWl1b3uCmb6yA0G+FouteAHAcLyYDiLRsW0BpIW6HpmGribR6MkhUoBkULqyshMUBB10Dy3sCMpBd+Fo5wJAJem20O20Kur4MaJX9HiaNd2Ri0RQmIhs9hfNImyw8Jm+/2JoF7XpkzzZg6BH/ozUrnXjpbGvtmQl9jLFFBkXFw==";
        String cipherText = "KrL0KDWoftJgNBkufrgk2hey4rRLJJxJQIxUXefcK1Xm3xWt5BDB92biYIcCwws+yfW++2zXrFK6CMLB7RDbetJjM+0bCk3B1T7O0wI06c/ZNfiwKW3JLcLRdgq4OVSzZkgyRn5VoxuJ3QYbcsUnRohBWkzS2LDe+n8rBpne/a0=";
        String aaaaaaaaaa = "fSGZlmhwHeW09IPOvBMJ0Uqz3rbCBE93EdO5Pth+ugsYPcHZc5zM78qDdjVWjK7px1ZQCXbSuroBZtKe1It0QwA0rvJx5ClK0yd2HJZwO/d1I7qXQ31I54xyKBTBuEa8Zlgmd36LWS/EBERBNCKTgZgj+oCO9PRnj+IMdQZ20Hg=";
// 解密后的明文应该为test
        String plainText = CryptoUtils.decryptByRSA(privateKey, cipherText);
        System.out.println("解密后的明文为：" + plainText);
    }

}